using System;
using System.Data;
using System.Xml;

using OR.Reuse.Persistence;

using Derived = OR.Lazarus.Library.CPP.Types;

namespace OR.Lazarus.Library.CPP.Types.Lazarus
{
	/// <summary>
	/// Defines a name within a context for a specific type.
	/// </summary>
   public class NameDetail : EntityBase
   {
		protected System.String mContext;
		protected System.String mValue;
		protected System.Boolean mSizeRequired;
		protected string mDescription;

		public NameDetail()
		{
	
		}
	
		/// <summary>
		/// 
		/// </summary>
		public System.String Context
		{
			get
			{
				return ( mContext );
			}
			set
			{
				mContext = value;
			}
		}

		/// <summary>
		/// 
		/// </summary>
		public System.String Value
		{
			get
			{
				return ( mValue );
			}
			set
			{
				mValue = value;
			}
		}

		/// <summary>
		/// 
		/// </summary>
		public System.Boolean SizeRequired
		{
			get
			{
				return ( mSizeRequired );
			}
			set
			{
				mSizeRequired = value;
			}
		}

		/// <summary>
		/// 
		/// </summary>
		public string Description
		{
			get
			{
				return ( mDescription );
			}
			set
			{
				mDescription = value;
			}
		}

		public override void LoadXml( XmlElement pSource )
		{
			// Scalar Values
			mContext = DataUtility.GetString( pSource, "context" );
			mValue = DataUtility.GetString( pSource, "value" );
			mSizeRequired = DataUtility.GetBool( pSource, "sizerequired", false );
			XmlElement vDescription = ( XmlElement )pSource.SelectSingleNode( "lzt:description", PersistenceConfig.Namespaces );
			
			if ( vDescription != null )
			{
				mDescription = vDescription.InnerText;
			}
			
		}
		
		public override XmlElement SaveXml( XmlDocument p_docContext )
		{
			XmlElement vNewElement	= p_docContext.CreateElement( "lzt", "name", "http://schemas.icitadel.com/Lazarus/CPP/Rules.xsd" );

			// Scalar Values
			if ( !String.IsNullOrEmpty( mContext ) )
			{
				vNewElement.SetAttribute( "context", mContext );
			}
					
			if ( !String.IsNullOrEmpty( mValue ) )
			{
				vNewElement.SetAttribute( "value", mValue );
			}
					
			vNewElement.SetAttribute( "sizerequired", mSizeRequired.ToString() );
			if ( !String.IsNullOrEmpty( mDescription ) )
			{
				XmlElement	vDescription = p_docContext.CreateElement( "lzt", "description", "http://schemas.icitadel.com/Lazarus/CPP/Rules.xsd" );
				vDescription.InnerText = mDescription;
				vNewElement.AppendChild( vDescription );
			}
					

			return ( vNewElement );
		}

		public virtual object Clone()
		{
			Derived.NameDetail v_oReturn = new Derived.NameDetail();
			
			v_oReturn.Context = mContext;
			v_oReturn.Value = mValue;
			v_oReturn.SizeRequired = mSizeRequired;
			v_oReturn.Description = mDescription;
			
			// FK Values

			// Collections
			
			return ( v_oReturn );
		}

		public virtual Derived.NameDetail CloneTyped()
		{
			return ( ( Derived.NameDetail )this.Clone() );
		}
   }
}
   